<template>
    <fieldset>
        编号：<input type="text" v-model='code'>
        品牌名称：<input type="text" v-model='productName'>
        <br>
        产品图片地址：<input type="text" v-model="imgSrc">
        价格：<input type="text" v-model="price">
        <br>
        <button @click='add'>添加</button>
    </fieldset>
</template>
<script>
    export default{
        data(){
            return{
                code:'',
                productName:'',
                imgSrc:'',
                price:''
            }
        },
        methods:{
            add(){
                if(!this.code||!this.productName||!this.imgSrc||!this.price){
                    return
                }
                let obj = {
                    id:Math.random().toString(32).substring(2),
                    code:this.code,
                    imgSrc:this.imgSrc,
                    productName:this.productName,
                    price:this.price,
                    total:this.price,
                    count:1
                }

                this.$emit('add',obj)

                this.code=''
                this.productName=''
                this.imgSrc=''
                this.price=''
            }
        }
    }

</script>